package com.ivo.core.hibernate;

/**
 * <h1>title</h1>
 * <p>
 * content
 * </p>
 * <b>Note:</b>
 *
 * @author nexf
 * @since 2017/3/7
 */
public class HqlHelper {

  public static String like(String arg) {
    return "%" + arg + "%";
  }

  public static String leftLike(String arg) {
    return arg + "%";
  }

  public static String rightLike(String arg) {
    return "%" + arg;
  }

  public static String removeSelect(String hql) {
    if (hql == null || hql.trim().equals("")) {
      return null;
    }
    String temp = hql.toLowerCase().trim();
    if (temp.startsWith("from")) {
      return hql;
    } else if (!temp.startsWith("select")) {
      return null;
    }
    int index = temp.indexOf("from");
    if (index == -1) {
      return null;
    }
    return hql.substring(index);
  }


}
